package com.iflytek.iot.common.monitor.handler;

import com.iflytek.iot.common.monitor.model.MonitorTask;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zurun
 * @date 2020/7/14 09:59:06
 */
public class MonitorHandler {

    public MonitorHandler() {
        new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    MonitorTask task = MonitorContent.take();
                    handle(task);
                } catch (InterruptedException e) {
//                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                    System.out.println("监控线程interrupted");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "iot-monitor-thread").start();
    }

    private void handle(MonitorTask task) {
        task.run();
    }
}
